using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

using GSN.Rules;
using GSN.Config;
using GSNConf.Rules.ConfigControls;
using GSNConf.GenConfigControls;

namespace GSNConf.Rules
{
    class AllowedTimeRuleConfigurator : IDictionaryConfigurator
    {
        #region IDictionaryConfigurator Members

        public override bool show()
        {
            GenConfigForm form = new GenConfigForm(new AllowedTimeRuleConfigControl(), "Rule Settings");

            string fromTime = null;
            fromTime = getItemString("From");
            /*if (data.ContainsKey("From"))
                 fromTime = data["From"];*/

            string toTime = null;
            toTime = getItemString("To");
            /*if (data.ContainsKey("To"))
                toTime = data["To"];*/

            // show old values, if any
            if (fromTime != null && toTime != null)
            {
                System.Windows.Forms.Control[] c =
                    form.Controls.Find("txtFrom", true);

                ((MaskedTextBox)c[0]).Text = fromTime;

                c =
                    form.Controls.Find("txtTo", true);

                ((MaskedTextBox)c[0]).Text = toTime;

            }

            if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                // save changes    
                System.Windows.Forms.Control[] c =
                    form.Controls.Find("txtFrom", true);

                setItemString(((MaskedTextBox)c[0]).Text, "From");
                //data["From"] = ((MaskedTextBox)c[0]).Text;
                
                c = form.Controls.Find("txtTo", true);

                setItemString(((MaskedTextBox)c[0]).Text, "To");
                //data["To"] = ((MaskedTextBox)c[0]).Text;

                return true;
            }

            return false;

        }

        #endregion
    }
}
